﻿<!DOCTYPE>
<html ng-app="forpwdApp" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, width=device-width, minimal-ui">
    <link href="/css/style.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" type="text/css" href="/css/pensonel.css" />
    <script src="/framework/angular-wang-editor/dist/js/lib/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="/framework/angular.min.js"></script>
    <title ng-bind="'忘记密码-'+systemTitle"></title>
</head>
<body>
    <section class="content">

<div class="signup " >

<div class="formsignup">
<div class="form-unit" ng-controller="forpwdCtrl" ng-cloak>

    <form class="Modify_password" name="myForm" ng-show="unameregis" novalidate>
        <div class="topsigunp"><img ng-src="{{orgLogo}}" src="/images/logo.png" onerror="javascript:this.src='/images/logo.png'" style="max-width: 256px;max-height: 80px;" ></div>
        <div class="form_title">忘记密码</div>
        <div class="form-field">
        <input type="text" name="username" id="username" placeholder="请填写邮箱/手机号" autocomplete="off" class="form-control email" ng-model="username" required  ng-pattern="/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}|1[3|4|5|7|8]\d{9}$/"  set-focus ng-focus="userNameOnFocus()" />
        </div>

           <div class="form-fidld errormsg" ng-show="myForm.username.$dirty && myForm.username.$invalid && !myForm.username.$focused">
  <span ng-show="myForm.username.$error.required">邮箱/手机号不能为空</span>
  <span class="warning" ng-show="myForm.username.$error.pattern">用户名格式不正确</span>
           </div>

         <div class="form-fidld errormsg" ng-show="unerr && !(myForm.username.$error.required||myForm.username.$error.pattern) ">
  <span ng-show="unerr">{{unerr_msg}}</span>
           </div>

        <button type="submit" class="btn submit form_btn" ng-disabled="myForm.$invalid" ng-click="resultpwd()" >重置密码</span>
        </button>
        <div class="form-field" ng-if="!otherPlace">
           <a class="info-wjmm" onclick="history.back()" >返回登录？</a>
            <!--<a class="info-zhuce" href="register.html">企业注册</a>-->
        </div>

    </form>

    <form class="phone_Modify_password" name="myForm2" ng-show="useremail" novalidate>
    
          <div class="topsigunp"><img ng-src="{{orgLogo}}" src="/images/logo.png" onerror="javascript:this.src='/images/logo.png'" width=232 height=80></div>
          <div class="info-field">
            <div class="form_title">重置密码邮件已经发送至邮箱<br>
          <span class="form_title_yx">{{username}}</span><br>
          有效期为2小时，请尽快核对
            </div>
</div><div class="form-field">
            <input type="text" name="txt_verify" placeholder="邮箱验证码" autocomplete="off" class="form-control verify" ng-model="txt_verify" required>
           <button type="button" class="timer" ng-show="!emailshow" ng-disabled="!emailshow">{{email_verify}}</button>
           <button type="button" class="timer  timerwc" ng-show="emailshow" ng-click="result_email()" >重新发送邮件</button>    
           </div>

           <div class="form-fidld errormsg" ng-show="myForm2.txt_verify.$dirty && myForm2.txt_verify.$invalid">          
  <span ng-show="myForm2.txt_verify.$error.required">邮箱验证码不能为空</span>
           </div>

           <div class="form-fidld errormsg" ng-show="email_err && !myForm2.txt_verify.$error.required">
  <span ng-show="email_err">{{sms_msg}}</span>
           </div>

           <button type="submit" class="btn form_btn submit" ng-click="sms_forpwd()" ng-disabled="myForm2.$invalid">重置密码</button>

    </form>

    <form class="phone_Modify_password" name="myForm3" ng-show="usermsg" novalidate>
       <div class="topsigunp"><img ng-src="{{orgLogo}}" src="/images/logo.png" onerror="javascript:this.src='/images/logo.png'" width=232 height=80></div>
          <div class="info-field">
            <div class="form_title">验证码已经发送至手机<br>
          <span class="form_title_phone"> {{username}}</span><br>
          有效期为2小时，请尽快核对
            </div>
          </div>
           <div class="form-field">            
            <input type="text" name="yanzhengma" id="yanzhengma" placeholder="验证码" autocomplete="off" class="form-control yzm" ng-model="yanzhengma" required  ng-focus/>
            <img ng-src="{{valimgurl}}" ng-click="upd_yzm()" class="timer  timerwc"/>
          </div>
          <div class="form-field">
            <input type="text" name="txt_verify" placeholder="短信验证码" autocomplete="off" class="form-control verify" ng-model="txt_verify" required>
            <button class="timer "  ng-show="!vershow">{{sms_verify}}</button>
            <button class="timer  timerwc" ng-click="send_sms()" ng-show="vershow" ng-disabled="myForm3.yanzhengma.$dirty && myForm3.yanzhengma.$invalid && !myForm3.yanzhengma.$focused">{{sms_verify}}</button>
          </div>

          <div class="form-fidld errormsg" ng-show="myForm3.txt_verify.$dirty && myForm3.txt_verify.$invalid">          
  <span ng-show="myForm3.txt_verify.$error.required">短信验证码不能为空</span>
           </div>

           <div class="form-fidld errormsg" ng-show="sms_err && !myForm3.txt_verify.$error.required">
  <span ng-show="sms_err">{{sms_msg}}</span>
           </div>
           <button type="submit" class="btn form_btn submit" ng-click="sms_forpwd()" ng-disabled="myForm3.$invalid" >重置密码</button>
    </form>

    <!--重置密码-->
    <form class="phone_Modify_password" name="myForm4" ng-show="updatePwd">
       <div class="topsigunp"><img ng-src="{{orgLogo}}" src="/images/logo.png" onerror="javascript:this.src='/images/logo.png'" width=232 height=80></div>
          <div class="info-field">
            <div class="form_title">更新密码</div>
          </div>
           <div class="form-field">            
            <input type="password" name="password" id="password" placeholder="新密码" autocomplete="off" class="form-control yzm" ng-model="password" ng-minlength="6" ng-maxlength="16"  required  ng-focus/>
          </div>
          <div class="form-field">
            <input type="password" name="password_two" id="password_two" placeholder="确认新密码" autocomplete="off" class="form-control verify" ng-model="password_two" required>
          </div>
          <div class="form-fidld errormsg" ng-show="uppwderr">
				<span>{{uppwderr_msg}}</span>
           </div>
           <button type="submit" class="btn form_btn submit" ng-click="upPwdFun()" >重置密码</button>
    </form>

    <!--重置密码成功-->
    <form class="login-was-successful" ng-show ="uppwdsuccess">
				<div class="topsigunp"><img ng-src="{{orgLogo}}" src="/images/logo.png" onerror="javascript:this.src='/images/logo.png'" alt=""></div>
				<div class="login-successful-img"><i class="iconfont">&#xe602;</i></div>
        <div class="form-field"><div class="form_title">密码修改成功，请重新登录！
        <br/><span class="form_title_yx">{{username}}</span><br/> 
        <!--<span>5</span>秒自动登录，如页面未加载请点击下方按钮。-->
        </div></div>
           <button type="submit" class="btn form_btn submit"  ng-if="!otherPlace" ng-click="location.href='/login.html'" >重新登录</button>

    </form>


</div>
</div>
</div>

</section>
    
    <script src="/framework/lodash.min.js" type="text/javascript"></script>
    <script src="/framework/restangular/restangular.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/framework/angular-toastr/angular-toastr.min.js"></script>
    <script type="text/javascript" src="/framework/angular-toastr/angular-toastr.tpls.min.js"></script>
    <script src="/system/service/common.js" type="text/javascript"></script>

    <script type="text/javascript">

        var mainApp = angular.module("forpwdApp", ['Common']);

        mainApp.directive('setFocus', function () {
            return function (scope, element) {
                element[0].focus();
            };
        });

        mainApp.directive('ngFocus', function () {
            //var FOCUS_CLASS = "ng-focused";
            return {
                restrict: 'A',
                require: 'ngModel',
                link: function (scope, element, attrs, ctrl) {
                    ctrl.$focused = true;
                    element.bind('focus', function (evt) {
                        //element.addClass(FOCUS_CLASS);
                        scope.$apply(function () {
                            ctrl.$focused = true;
                        });
                    }).bind('blur', function () {
                        //element.removeClass(FOCUS_CLASS);
                        scope.$apply(function () {
                            ctrl.$focused = false;
                        })
                    })
                }
            }
        });


        mainApp.config(['toastrConfig', '$locationProvider', function (toastrConfig, $locationProvider) { $locationProvider.html5Mode({ enabled: true, requireBase: false }); } ]).controller('forpwdCtrl', ['$scope', '$location', 'RequestUserService', '$interval', 'Restangular', function ($scope, $location, RM, $interval,Restangular) {
            Restangular.addFullRequestInterceptor(function(element, operation, route, url, headers, params, httpConfig) {     
                return {              
                    headers: {"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"}  
                };
            });

            $scope.unameregis = true; //找回密码第一步（display）
            $scope.useremail = false; //找回密码 email
            $scope.usermsg = false; //找回密码 sms
            $scope.updatePwd = false; //显示修改密码框
            $scope.uppwderr = false; //显示修改密码是否错误
            $scope.uppwderr_msg = ""; //修改密码错题提示
            $scope.uppwdsuccess = false; //修改密码是否成功

            $scope.unerr = false; //找回密码帐号验证
            $scope.sms_msg = ''; //找回密码帐号验证 返回信息

            $scope.sms_err = false; //短信验证码输入错误（display）
            $scope.email_err = false; //邮箱验证码输入错误（display）
            $scope.sms_msg = ""; //短信验证码输入错误信息


            $scope.sms_verify = '发送验证码'; //重新发送短信
            $scope.email_verify = '重新发送邮件(60)'; //重新发送邮件
            $scope.num1 = 60; //发送邮件倒计时
            $scope.num2 = 60; //发送短信倒计时
            $scope.vershow = true; //短信倒计时（display）
            $scope.emailshow = false; //邮件倒计时（display）
            $scope.jishiqi = "";

            $scope.otherPlace = true; //是否为其他其他引入改页面，需要隐藏登录按钮
            // 获得焦点时初始化参数
            $scope.userNameOnFocus = function () {
                $scope.unerr = false; //注册第二步error提示短信（display）
                $scope.unerr_msg = "";
            }
            //先替换logo
            $scope.enterprise = $location.hash();
            if (!$scope.enterprise) {
                $scope.enterprise = $location.search().o;
            }
            $scope.orgLogo = commonFileUrl + "/resources/logo/" + $scope.enterprise + "_1.png?" + new Date();

            $scope.password = "";
            $scope.password_two = "";
            $scope.upPwdFun = function () {
                if ($scope.password == undefined || $scope.password_two == undefined || $scope.password.length <= 0 || $scope.password_two.length <= 0) {
                    $scope.uppwderr = true;
                    $scope.uppwderr_msg = "请输入密码，并再次确认密码！";
                    return;
                }
                if ($scope.password.length < 6 || $scope.password.length > 18) {
                    $scope.uppwderr = true;
                    $scope.uppwderr_msg = "密码长度只能为6-18位！";
                    return;
                }
                if ($scope.password != $scope.password_two) {
                    $scope.uppwderr = true;
                    $scope.uppwderr_msg = "两次密码输入不一致！";
                    return;
                }
                $scope.uppwderr = false;
                RM.resetPwd({ pwd: $scope.password, code: $scope.code }).then(function (users) {
                    if (users.errorcode == 0) {
                        $scope.uppwderr = false;
                        $scope.uppwdsuccess = true;
                        $scope.updatePwd = false;
                    } else {
                        $scope.uppwderr = true;
                        $scope.uppwderr_msg = users.errormsg;
                    }
                }, function errorCallback() {
                    $scope.uppwderr = true;
                    $scope.uppwderr_msg = "连接服务器失败！";
                });

            }

            $scope.QueryString = function (fieldName) {
                /// <summary>
                ///   获得URL GET参数  
                /// </summary>
                /// <param name="fieldName" type="String">
                ///   参数名
                /// </param>
                /// <returns type="void" />如果不存在返回NULL
                var reg = new RegExp("(^|&)" + fieldName.toLowerCase() + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
            if ($scope.QueryString("wx") == undefined) {
                $scope.otherPlace = true;
            }
            //更新验证码
            $scope.upd_yzm = function () {
                //Restangular.one("/ApiUser/").customGET("verifyCode",
                RM.verifyCode({ useraccount: $scope.username }).then(function (users) {
                    if (users.errorcode == 0) {
                        $scope.loginerr = false;
                        $scope.valimgurl = users.imgsrc;
                    } else {
                        $scope.unerr = true;
                        $scope.unerr_msg = "验证码获取失败！";
                    }
                }, function errorCallback() {
                    $scope.unerr = true;
                    $scope.unerr_msg = "连接服务器失败！";
                });
            }

            $scope.resultpwd = function () { //重置密码帐号验证
                var username1 = $scope.username;
                //Restangular.one("/ApiUser/").customPOST({ name: "My Message" }, "isAccount", 
                RM.isAccount({ useraccount: $scope.username }).then(function (retData) {
                    if (retData.errorcode == "1") {
                        //4账号不存在（成功） 1账号已存在 3账号格式不正确 5连接不上数据库 6系统内部错误
                        if (username1.indexOf("@") >= 1) {
                            $scope.unameregis = false;
                            $scope.useremail = true;
                            $scope.result_email();
                            $scope.num1 = 60;
                            //邮箱发送倒计时
                            if (!$scope.jishiqi) {
                                $scope.jishiqi = $interval(function () {
                                    if ($scope.num1 <= 0) {
                                        $scope.email_verify = "重新发送邮件";
                                        $scope.emailshow = true;
                                    } else {
                                        $scope.email_verify = "重新发送邮件(" + $scope.num1 + ")";
                                        $scope.num1 = $scope.num1 - 1;
                                    }
                                }, 1000);
                            }
                        } else {
                            $scope.unameregis = false;
                            $scope.usermsg = true;
                            $scope.upd_yzm();
                            //短信发送倒计时
                            //                            $interval(function () {
                            //                                if ($scope.num2 <= 0) {
                            //                                    $scope.sms_verify = "重发验证码";
                            //                                    $scope.vershow = true;
                            //                                } else {
                            //                                    $scope.sms_verify = "重新发送(" + $scope.num2 + ")";
                            //                                    $scope.num2 = $scope.num2 - 1;
                            //                                }
                            //                            }, 1000);

                        }
                    } else {
                        $scope.unerr = true;
                        if (retData.errorcode == "3") { $scope.sms_msg = "账号格式不正确"; }
                        else if (retData.errorcode == "4") { $scope.unerr_msg = "帐号不存在！"; }
                        else if (retData.errorcode == "5") { $scope.sms_msg = "连接不上数据库"; }
                        else if (retData.errorcode == "6") { $scope.sms_msg = "系统内部错误"; }
                    }
                }, function errorCallback() {
                    $scope.unerr = true;
                    $scope.sms_msg = "连接服务器失败！";
                }
                );
            }

            //用户发送短信验证码
            $scope.send_sms = function () {
                $scope.vershow = false;
                $scope.num2 = 60;
                //                Restangular.one("/ApiUser/").customPOST({ name: "My Message" }, "sendSMS", 
                RM.sendSMS({ useraccount: $scope.username, option: "update", code: $scope.yanzhengma }).then(function (retData) {
                    //短信发送倒计时
                    if (!$scope.jishiqi) {
                        $scope.jishiqi = $interval(function () {
                            if ($scope.num2 <= 0) {
                                $scope.sms_verify = "重发验证码";
                                $scope.vershow = true;
                            } else {
                                $scope.sms_verify = "重新发送(" + $scope.num2 + ")";
                                $scope.num2 = $scope.num2 - 1;
                            }
                        }, 1000);
                    }
                    if (retData.errorcode == "0") {
                        //                    errorcode true string 返回信息： 0发送成功 （2账号已存在 3账号信息有误）【防止恶意修改】 5连接不上数据库 6系统内部错误
                        console.log(retData);
                    } else {
                        $scope.unerr = true;
                        if (retData.errorcode == "3") { $scope.sms_msg = "账号信息有误"; }
                        else if (retData.errorcode == "5") { $scope.sms_msg = "连接不上数据库"; }
                        else if (retData.errorcode == "6") { $scope.sms_msg = "系统内部错误"; }
                        else if (retData.errorcode == "14") { $scope.sms_msg = "图片验证码输入错误"; }
                        else if (retData.errorcode == "45") { $scope.sms_msg = "图片验证码超时"; }
                    }
                }, function errorCallback() {
                    $scope.unerr = true;
                    $scope.sms_msg = "连接服务器失败！";
                });
            }

            //重新发送激活邮箱
            $scope.result_email = function () {
                $scope.num1 = 60;
                $scope.emailshow = false;

                //                Restangular.one("/ApiUser/").customPOST({ name: "My Message" }, "sendEmail", 
                RM.sendEmail({ useraccount: $scope.username, option: "updatapwd" }).then(function (retData) {
                    if (retData.errorcode == "0") {
                        //                    errorcode true string 返回信息： 0发送成功 （2账号已存在 3账号信息有误）【防止恶意修改】 5连接不上数据库 6系统内部错误
                        console.log(retData);
                        $scope.code = retData.code;
                        $scope.updatePwd = true;
                        $scope.useremail = false;
                    } else {
                        $scope.unerr = true;
                        if (retData.errorcode == "3") { $scope.sms_msg = "账号信息有误"; }
                        else if (retData.errorcode == "5") { $scope.sms_msg = "连接不上数据库"; }
                        else if (retData.errorcode == "6") { $scope.sms_msg = "系统内部错误"; }
                        else if (retData.errorcode == "21") { $scope.sms_msg = "未发送邮件"; }
                    }
                }, function errorCallback() {
                    $scope.unerr = true;
                    $scope.sms_msg = "连接服务器失败！";
                });

                //                console.log("重新发送激活邮箱");
            }

            $scope.code = "";
            //短信重置密码
            $scope.sms_forpwd = function () {
                //Restangular.one("/ApiUser/").customPOST({ name: "My Message" }, "verifySMS", 
                RM.verifySMS({ useraccount: $scope.username, code: $scope.txt_verify }).then(function (retData) {
                    //返回代码： 0验证成功 10验证码超时 14验证码输入错误 3账号信息有误 4不在此账号 5连接不上数据库 6系统内部错误
                    if (retData.errorcode == "0") {

                        $scope.code = retData.code;
                        $scope.useremail = true;
                        $scope.usermsg = false;
                    } else {
                        $scope.sms_err = true; //短信验证码输入错误（display）
                        $scope.email_err = true;
                        if (retData.errorcode == "14") { $scope.sms_msg = "验证码信息输入错误"; }
                        else if (retData.errorcode == "10") { $scope.sms_msg = "验证码超时"; }
                        else if (retData.errorcode == "3") { $scope.sms_msg = "账号信息有误"; }
                        else if (retData.errorcode == "4") { $scope.sms_msg = "不在此账号"; }
                        else if (retData.errorcode == "5") { $scope.sms_msg = "连接不上数据库"; }
                        else if (retData.errorcode == "6") { $scope.sms_msg = "系统内部错误"; }
                    }
                }, function errorCallback() {
                    $scope.sms_err = true;
                    $scope.sms_msg = "连接服务器失败！";
                });
            }

        } ]);


    </script>
    <script src="/system/service/userpathservice.js" type="text/javascript"></script>
</body>
</html>
